<script>
	export default {
		globalData: {
			screenWidth: 0,
			screenHeight: 0,
			windowWidth: 0,
			windowHeight: 0,
			statusBarHeight: 0,
			menuButtonInfo: [],
		},
		onLaunch() {
			let _this = this;
			uni.getSystemInfo({
				success: function(res) {
	
					let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
					_this.$options.globalData.screenWidth = res.screenWidth; //屏幕宽度
					_this.$options.globalData.screenHeight = res.screenHeight; //屏幕高度
					_this.$options.globalData.windowWidth = res.windowWidth; //可使用窗口宽度
					_this.$options.globalData.windowHeight = res.safeArea.height - res.safeArea
						.top; //可使用窗口高度
					_this.$options.globalData.statusBarHeight = res.statusBarHeight; //可使用窗口高度
					_this.$options.globalData.menuButtonInfo = menuButtonInfo; //可使用窗口高度
	
				}
			})
		},
		methods: {
			// 时间解析函数
			commentTimeHandle(dateStr) {
				// dateStr = 2018-09-06 18:47:00" 测试时间
				
				var tim = new Date(dateStr).getTime()
				var dateTimeStamp = new Date(dateStr).getTime();
				
				var minute = 1000 * 60; //把分，时，天，周，半个月，一个月用毫秒表示
				var hour = minute * 60;
				var day = hour * 24;
				var week = day * 7;
				var halfamonth = day * 15;
				var month = day * 30;
				var now = new Date().getTime(); //获取当前时间毫秒
				var diffValue = now - dateTimeStamp; //时间差
				// console.log(diffValue)
				if (diffValue < 0) {
					console.log("diffValue<0", datetime, dateTimeStamp, now, diffValue);
					return '刚刚';
				}
				var minC = diffValue / minute; //计算时间差的分，时，天，周，月
				var hourC = diffValue / hour;
				var dayC = diffValue / day;
				var weekC = diffValue / week;
				var monthC = diffValue / month;
				var result = "2";
				if (monthC >= 1 && monthC <= 3) {
					result = " " + parseInt(monthC) + "月前"
				} else if (weekC >= 1 && weekC <= 3) {
					result = " " + parseInt(weekC) + "周前"
				} else if (dayC >= 1 && dayC <= 6) {
					result = " " + parseInt(dayC) + "天前"
				} else if (hourC >= 1 && hourC <= 23) {
					result = " " + parseInt(hourC) + "小时前"
				} else if (minC >= 1 && minC <= 59) {
					result = " " + parseInt(minC) + "分钟前"
				} else if (diffValue >= 0 && diffValue <= minute) {
					result = "刚刚"
				} else {
					var datetime = new Date();
					datetime.setTime(dateTimeStamp);
					var Nyear = datetime.getFullYear(); {}
					var Nmonth = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
					var Ndate = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
					var Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
					var Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
					var Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
					result = Nyear + "-" + Nmonth + "-" + Ndate
				}
				return result;
			},
		}
	}
</script>

<style>
	
	/*每个页面公共css */
	.row {
		display: flex;
		flex-direction: row;
	}
	
	.center {
		justify-content: center;
		align-items: center;
	}
	
	.items {
		align-items: center;
	}
	
	.justify {
		justify-content: center;
	}
	
	.around {
		justify-content: space-around;
	}
	
	.between {
		justify-content: space-between;
	}
	
	.juend {
		justify-content: flex-end;
	}
	
	.start {
		align-items: flex-start;
	}
	
	.end {
		align-items: flex-end;
	}
	
	.column {
		display: flex;
		flex-direction: column;
	}
	
	.line {
		overflow: hidden;
		-webkit-line-clamp: 1;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}
</style>
